package com.collectionAndMap.collection.list;

import java.util.Iterator;
import java.util.LinkedList;

/***
 * @ClassName: LinkedListDemo
 * @Description: 双向链表
 * @Auther: 送一一块二向箔
 * @Date: 16:30 2022/2/15
 * @version : V1.0
 */
public class LinkedListDemo {

    public static void main(String[] args) {

        test();
    }
    public static void test(){
        LinkedList<Student> list = new LinkedList<>();

        Student s1 = new Student("aaa", 1, "1");
        Student s2 = new Student("bbb",2,"0");
        Student s3 = new Student("ccc",3,"0");
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s1);
        System.out.println(list);

        //默认先删除下标小的元素
        list.remove(s1);
        System.out.println(list);


        //重写equal实现删除
        list.remove(new Student("aaa", 1, "1"));
        System.out.println("删除以后的"+list);

        System.out.println(list.get(1));

        Iterator<Student> iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}
